package com.shuqi.activity.viewport;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.os.Handler;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

import com.shuqi.activity.ActivityManager;
import com.shuqi.activity.BookContentActivity;
import com.shuqi.activity.BookCoverActivity;
import com.shuqi.activity.LoginActivity;
import com.shuqi.activity.PayActivity;
import com.shuqi.activity.viewport.PriceChangeDialog.onPriceListener;
import com.shuqi.application.ShuqiApplication;
import com.shuqi.common.Constant;
import com.shuqi.common.RefreshBalanceTask;
import com.shuqi.common.RefreshBalanceTask.RefreshBlanceListener;
import com.shuqi.common.utils.Log4an;
import com.shuqi.common.utils.ToastUtil;
import com.shuqi.controller.R;
import com.shuqi.database.dao.impl.BookInfoDao;
import com.shuqi.database.model.BookInfo;
import com.shuqi.database.model.BookMarkInfo;
import com.shuqi.database.model.UserInfo;
import com.shuqi.model.bean.BuyBookInfo;
import com.shuqi.model.bean.ChapterInfo;
import com.shuqi.model.bean.OrderInfo;
import com.shuqi.model.manager.BookCatalogManager;
import com.shuqi.model.manager.BuyBookManager;
import com.shuqi.model.manager.BuyBookManager.BuyChapterInfoInterface;
import com.shuqi.model.manager.MyAccountManager;
import com.shuqi.statistics.StatisticsEventID;
import com.shuqi.statistics.StatisticsUtils;

public class OrderDialog implements OnClickListener, OnDismissListener {
    private final String logTag = "Order";
    private Activity context;
    private BottomDialog dialog;
    private View view;
    private OrderInfo orderInfo;

    private final int MSG_FAIL = -1;// 按章
    // private final int MSG_REFRESH = 0;
    private final int MSG_REFRESH_OK = 1;
    private final int MSG_REFRESH_ERROR = 2;

    private final int MSG_BUY_CHAPTER_SUCCESS = 3;// 按章成功
    private final int MSG_BUY_BOOK_SUCCESS = 5;// 按本成功
    private final int MSG_BUY_LOADING = 4;
    private final int MSG_RETURN_10 = 10;// 返回结果为10
    private final int MSG_RETURN_CHAPTER_13 = 13;// 按章
    private final int MSG_RETURN_BOOK_14 = 14;// 按本
    private final int MSG_RETURN_CHAPTER_15 = 15;
    private final int MSG_RETURN_BOOK_16 = 16;

    private final String RETURN_OK = "1";
    private final String RETURN_NO_LOGIN = "10";// 未登录
    private final String RETURN_BUY_FAIL = "13";// 变动价格
    private final String RETURN_BOOK_SOLDOUT = "14";// 书籍关闭
    private ChapterInfo bookInfo;

    private boolean isNight;
    private boolean isVertial;

    private OnOrderDialogListener mOnOrderDialogListener;

    public void setmOnOrderDialogListener(OnOrderDialogListener mOnOrderDialogListener) {
        this.mOnOrderDialogListener = mOnOrderDialogListener;
    }

    public interface OnOrderDialogListener {
        /** 按章购买成功后刷新界面 */
        public void refreshPage(ChapterInfo bookInfo, boolean isShowDialog);

        /** 按本购买成功后刷新阅读页UI */
        public void refreshDownView();

        public void onOrderDialogDismiss();

    }

    private Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
                case MSG_FAIL:
                    String s = "购买失败";
                    if (bookInfo != null && !TextUtils.isEmpty(bookInfo.getMsg())) {
                        s = bookInfo.getMsg();
                    }
                    if (mBuyBookInfo != null && !TextUtils.isEmpty(mBuyBookInfo.getInfo())) {
                        s = mBuyBookInfo.getInfo();
                    }
                    showBuyFailed(s);
                    break;
                case MSG_REFRESH_OK:
                    Log4an.i(logTag, "refresh balance...ok");
                    initViews();
                    break;
                case MSG_REFRESH_ERROR:
                    ToastUtil.showToastFullyCustomizable(context, "获取余额失败...");
                    break;
                case MSG_BUY_CHAPTER_SUCCESS:
                    if (context instanceof BookContentActivity) {
                        if (bookInfo != null) {
                            getAutoBuyState(bookInfo.getBookId(),
                                    MyAccountManager.getInstance(context).getUserId());
                        }
                        if (mOnOrderDialogListener != null) {
                            mOnOrderDialogListener.refreshPage(bookInfo, true);
                        }
                        Log4an.i("yjd", "orderInfo.getPayMode()=" + orderInfo.getPayMode());
                        if (orderInfo.getPayMode() == 1) {
                            updateBookCatalog(mBuyBookInfo.getIsUpdateCatalog());
                        } else {
                            updateChapterCatalog(bookInfo.getIsUpdateCatalog());
                        }
                    }
                    break;
                case MSG_BUY_BOOK_SUCCESS:
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                    showBuyBookToast();
                    if (mBuyBookInfo != null) {
                        updateBookCatalog(mBuyBookInfo.getIsUpdateCatalog());
                    }
                    if (mOnOrderDialogListener != null) {
                        mOnOrderDialogListener.refreshDownView();
                    }
                    break;
                case MSG_BUY_LOADING:
                    setGoneOrderContent();
                    if (context instanceof BookCoverActivity) {
                        ((BookCoverActivity) context).mBuyBookOnline();
                    }
                    break;
                case MSG_RETURN_10:
                    dismiss();
                    LoginActivity.openVerifyForResult(context, LoginActivity.LOGINTYPE_VERIFY);
                    break;
                case MSG_RETURN_CHAPTER_13: {
                    dismiss();
                    PriceChangeDialog mPriceChangeDialog =
                            new PriceChangeDialog(context, orderInfo, new onPriceListener() {

                                @Override
                                public String getOldPrice() {
                                    return orderInfo.getPrice();
                                }

                                @Override
                                public String getNewPrice() {
                                    return bookInfo.getCurChapterPrice();
                                }
                            });
                    mPriceChangeDialog.show();
                    updateChapterCatalog(bookInfo.getIsUpdateCatalog());
                    StatisticsUtils.onEvent(context, StatisticsEventID.BOOKCONTENT_PRICE_CHANGE);
                }
                    break;
                case MSG_RETURN_BOOK_14: {
                    dismiss();

                    PriceChangeDialog mPriceChangeDialog =
                            new PriceChangeDialog(context, orderInfo, new onPriceListener() {

                                @Override
                                public String getOldPrice() {
                                    return orderInfo.getPrice();
                                }

                                @Override
                                public String getNewPrice() {
                                    return mBuyBookInfo.getCurChapterPrice();
                                }
                            });
                    mPriceChangeDialog.show();
                    updateBookCatalog(mBuyBookInfo.getIsUpdateCatalog());
                    StatisticsUtils.onEvent(context, StatisticsEventID.BOOKCONTENT_PRICE_CHANGE);
                }
                case MSG_RETURN_CHAPTER_15:
                    dismiss();
                    showBuySuccessful(true);
                    break;
                case MSG_RETURN_BOOK_16:
                    showBuyBookToast();
                    break;
            }
        };
    };

    /**
     * 更新目录:0,不更新；1,更新
     * 
     * @param retrunVal
     */
    private void updateChapterCatalog(String retrunVal) {
        if (bookInfo == null) {
            return;
        }
        Log4an.i("yjd", "retrunVal=" + retrunVal);
        if (RETURN_OK.equals(retrunVal)) {
            Log4an.i("yjd", "bid=" + bookInfo.getBookId() + ",uid=" + bookInfo.getBookId());
            BookCatalogManager.asyncDownloadCatalog(bookInfo.getBookId(), null, MyAccountManager
                    .getInstance(context).getUserId(), BookMarkInfo.TYPE_NEW_PAY_BOOKMARK);
        }
    }

    private void updateBookCatalog(String retrunVal) {
        if (mBuyBookInfo == null) {
            return;
        }
        if (RETURN_OK.equals(retrunVal)) {
            BookCatalogManager.asyncDownloadCatalog(mBuyBookInfo.getBookId(), null,
                    MyAccountManager.getInstance(context).getUserId(),
                    BookMarkInfo.TYPE_NEW_PAY_BOOKMARK);
        }
    }

    public OrderDialog(Activity context, OrderInfo orderInfo, boolean isNight, boolean isVertial) {
        this.context = context;
        this.orderInfo = orderInfo;
        this.isNight = isNight;
        this.isVertial = isVertial;
        if (isNight) {
            if (isVertial) {
                view = View.inflate(context, R.layout.view_dialog_order_night, null);
            } else {
                view = View.inflate(context, R.layout.view_dialog_order_horrizion_night, null);
            }
        } else {
            if (isVertial) {
                view = View.inflate(context, R.layout.view_dialog_order, null);
            } else {
                view = View.inflate(context, R.layout.view_dialog_order_horrizion, null);
            }
        }
        dialog = new BottomDialog(context, view);
        dialog.setOnDismissListener(this);
        initViews();
        refreshBalance();
    }

    /** 勾选确认CheckBox */
    private CheckBox mCheckBox;

    private void initViews() {
        if (orderInfo != null) {
            mCheckBox = (CheckBox) view.findViewById(R.id.view_dialog_order_checkbox);
            ((TextView) view.findViewById(R.id.view_dialog_order_bookname)).setText("书　　名："
                    + orderInfo.getBookName());
            if (orderInfo.getPayMode() == 1) {
                ((TextView) view.findViewById(R.id.view_dialog_order_chapter)).setText("购买内容："
                        + "全本");
                view.findViewById(R.id.check_layout).setVisibility(View.GONE);
            } else {
                ((TextView) view.findViewById(R.id.view_dialog_order_chapter)).setText("购买内容："
                        + orderInfo.getOrderDetail());
                view.findViewById(R.id.check_layout).setVisibility(View.VISIBLE);
            }
            ((TextView) view.findViewById(R.id.view_dialog_order_price)).setText("所需书豆："
                    + orderInfo.getPrice());

            UserInfo userInfo = MyAccountManager.getInstance(ShuqiApplication.getContext(), true);
            if (isNight) {
                ((TextView) view.findViewById(R.id.view_dialog_order_balance)).setText(Html
                        .fromHtml("账户余额：<font color=#0c6b47>"
                                + (TextUtils.isEmpty(userInfo.getBalance()) ? "0" : userInfo
                                        .getBalance()) + "</font>书豆"));
            } else {
                ((TextView) view.findViewById(R.id.view_dialog_order_balance)).setText(Html
                        .fromHtml("账户余额：<font color=#15be7b>"
                                + (TextUtils.isEmpty(userInfo.getBalance()) ? "0" : userInfo
                                        .getBalance()) + "</font>书豆"));
            }

            view.findViewById(R.id.view_dialog_order_refresh).setOnClickListener(this);

            TextView button = (TextView) view.findViewById(R.id.view_dialog_order_pay);
            button.setOnClickListener(this);
            if (isBalanceEnough(userInfo.getBalance())) {
                button.setText("确认购买");
                if (isNight) {
                    button.setBackgroundResource(R.drawable.common_btn_orange_night);
                } else {
                    button.setBackgroundResource(R.drawable.btn_common_orange);
                }
            } else {
                button.setText("充值");
                if (isNight) {
                    button.setBackgroundResource(R.drawable.common_btn_green_night);
                } else {
                    button.setBackgroundResource(R.drawable.btn_common_green_ok);
                }
            }
            if (context instanceof BookCoverActivity) {
                mCheckBox.setVisibility(View.GONE);
            } else if (context instanceof BookContentActivity) {
                if (orderInfo.getPayMode() == 1) {
                    mCheckBox.setVisibility(View.GONE);
                    StatisticsUtils.onEvent(context,
                            StatisticsEventID.BOOKCONTENT_ENTER_ORDER_CHAPTER);
                } else {
                    mCheckBox.setVisibility(View.VISIBLE);
                    mCheckBox.setOnClickListener(this);
                    BookInfo bookInfo =
                            BookInfoDao.getInstance().getBookInfo(null, orderInfo.getBookId(),
                                    MyAccountManager.getInstance(context).getUserId());
                    if (bookInfo != null) {
                        if (BookInfo.DEFAULT_NO_AUTO_BUY == bookInfo.getBookAutoBuyState()) {
                            mCheckBox.setChecked(true);
                        } else if (BookInfo.NO_AUTO_BUY == bookInfo.getBookAutoBuyState()) {
                            mCheckBox.setChecked(false);
                        }
                    }
                    StatisticsUtils
                            .onEvent(context, StatisticsEventID.BOOKCONTENT_ENTER_ORDER_BOOK);
                }
            }
        }
    }

    public boolean isShowing() {
        if (dialog != null)
            return dialog.isShowing();
        return false;
    }


    /** 刷新余额:回调 */
    private RefreshBlanceListener listener;

    /** 刷新余额 */
    private void refreshBalance() {
        if (listener == null) {
            listener = new RefreshBlanceListener() {
                @Override
                public void onFinish(boolean isSuccess, String balance) {
                    if (isSuccess) {
                        handler.sendEmptyMessage(MSG_REFRESH_OK);
                    } else {
                        handler.sendEmptyMessage(MSG_REFRESH_ERROR);
                    }
                }
            };
        }
        RefreshBalanceTask.getInstance().refreshBalanceOnline(listener);
    }

    /** 显示订单对话框 */
    public void show() {
        dialog.setDissmisOnClickOutSide(true);

        if (dialog != null && !dialog.isShowing()) {
            view.findViewById(R.id.buyLoading).setVisibility(View.GONE);
            view.findViewById(R.id.orderContent).setVisibility(View.VISIBLE);
            dialog.show();
        }
    }

    /** 隐藏订单对话框 */
    public void dismiss() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    /** 当前余额购买此内容是否充足 */
    private boolean isBalanceEnough() {
        UserInfo userInfo = MyAccountManager.getInstance(ShuqiApplication.getContext());
        return isBalanceEnough(userInfo.getBalance());
    }

    /** 当前余额购买此内容是否充足 */
    private boolean isBalanceEnough(String userBalance) {
        if (orderInfo != null) {
            try {
                float price = Float.valueOf(orderInfo.getPrice());
                float balance = TextUtils.isEmpty(userBalance) ? 0 : Float.valueOf(userBalance);
                return price <= balance;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return false;
    }

    private void getAutoBuyState(String bid, String uid) {
        BookInfo bookInfo = BookInfoDao.getInstance().getBookInfo(null, bid, uid);
        int state = bookInfo.getBookAutoBuyState();
        Log4an.i("yjd", "【orderDialog】state=" + state);
        if (state == BookInfo.DEFAULT_NO_AUTO_BUY) {
            BookInfoDao.getInstance().updateAutoBuyBookState(bookInfo.getBookId(), null,
                    MyAccountManager.getInstance(context).getUserId(), BookInfo.AUTO_BUY);
        } else if (state == BookInfo.NO_AUTO_BUY) {
            BookInfoDao.getInstance().updateAutoBuyBookState(bookInfo.getBookId(), null,
                    MyAccountManager.getInstance(context).getUserId(), BookInfo.NO_AUTO_BUY);
        }
    }

    private BuyBookInfo mBuyBookInfo;

    /**
     * 全本购买
     */
    private void buyBook() {
        StatisticsUtils.onEvent(context, StatisticsEventID.BOOKCONTENT_CLICK_BUY_BOOK);
        setGoneOrderContent();
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    Log4an.e(
                            "yjd",
                            "【发送全本购买】bid=" + orderInfo.getBookId() + ",cid="
                                    + orderInfo.getChapterId());
                    BuyBookInfo buyBookInfo =
                            BuyBookManager.buyBookOnline(context, orderInfo.getBookId(), orderInfo
                                    .getChapterId(), MyAccountManager.getInstance(context)
                                    .getUserId(), orderInfo.getPrice()); // 打开即为请求购买全本orderInfo.getPrice()
                    Log4an.e("yjd", "【全本购买】getType=" + buyBookInfo.getType());
                    Log4an.e(
                            "yjd",
                            "[返回]bid=" + buyBookInfo.getBookId() + ",update="
                                    + buyBookInfo.getIsUpdateCatalog() + ",price="
                                    + buyBookInfo.getCurChapterPrice() + ",msg="
                                    + buyBookInfo.getInfo());
                    if (RETURN_OK.equals(buyBookInfo.getType())) {
                        mBuyBookInfo = buyBookInfo;
                        handler.sendEmptyMessage(MSG_BUY_BOOK_SUCCESS);
                    } else if (RETURN_NO_LOGIN.equals(buyBookInfo.getType())) {
                        handler.sendEmptyMessage(MSG_RETURN_10);
                    } else if (RETURN_BUY_FAIL.equals(buyBookInfo.getType())) {
                        mBuyBookInfo = buyBookInfo;
                        handler.sendEmptyMessage(MSG_RETURN_BOOK_14);
                    } else if (RETURN_BOOK_SOLDOUT.equals(buyBookInfo.getType())) {
                        mBuyBookInfo = buyBookInfo;
                        handler.sendEmptyMessage(MSG_RETURN_BOOK_16);
                    } else {
                        mBuyBookInfo = buyBookInfo;
                        handler.sendEmptyMessage(MSG_FAIL);
                    }
                } catch (Exception e) {
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                    return;
                }

            }
        }).start();

    }

    /**
     * 按章购买
     */
    private void buyChapter() {
        // 按章购买
        Log4an.e("yjd", "【购买】bid=" + orderInfo.getBookId() + ",cid=" + orderInfo.getChapterId()
                + ",uid=" + MyAccountManager.getInstance(context).getUserId() + ",price="
                + orderInfo.getPrice());
        setGoneOrderContent();
        StatisticsUtils.onEvent(context, StatisticsEventID.BOOKCONTENT_CLICK_BUY_CHAPTER);
        try {
            BuyBookManager.buyChapterOnline(context, orderInfo.getBookId(),
                    orderInfo.getChapterId(), MyAccountManager.getInstance(context).getUserId(),
                    new BuyChapterInfoInterface() {

                        @Override
                        public void onFinish(ChapterInfo info) {

                            Log4an.e("yjd", "返回状态：" + info.getCurChapterType());
                            Log4an.e(
                                    "yjd",
                                    "[返回]bid=" + info.getBookId() + ",update="
                                            + info.getIsUpdateCatalog() + ",price="
                                            + info.getCurChapterPrice() + ",msg=" + info.getMsg()
                                            + "章节ID：" + orderInfo.getChapterId());
                            if (RETURN_OK.equals(info.getCurChapterType())) {
                                bookInfo = info;
                                handler.sendEmptyMessage(MSG_BUY_CHAPTER_SUCCESS);
                            } else if (RETURN_NO_LOGIN.equals(info.getCurChapterType())) {
                                handler.sendEmptyMessage(MSG_RETURN_10);
                            } else if (RETURN_BUY_FAIL.equals(info.getCurChapterType())) {
                                bookInfo = info;
                                handler.sendEmptyMessage(MSG_RETURN_CHAPTER_13);
                            } else if (RETURN_BOOK_SOLDOUT.equals(info.getCurChapterType())) {
                                bookInfo = info;
                                handler.sendEmptyMessage(MSG_RETURN_CHAPTER_15);
                            } else {
                                bookInfo = info;
                                handler.sendEmptyMessage(MSG_FAIL);
                            }
                            dialog.setCancelable(true);
                        }
                    }, orderInfo.getPrice());// orderInfo.getPrice()
        } catch (Exception e) {
            e.printStackTrace();
            // handler.sendEmptyMessage(buy_successful);
            // if (orderInfo != null && !TextUtils.isEmpty(orderInfo.getBookId())) {
            // Toast.makeText(context, "帐号是8000000，不能购买", Toast.LENGTH_LONG).show();
            // }
            return;
        }

    }

    private boolean isOnclickPay;

    public boolean getIsOnclickPay() {
        return isOnclickPay;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.view_dialog_order_refresh:
                refreshBalance();
                if (context instanceof BookContentActivity) {
                    if (orderInfo.getPayMode() == 1) {
                        StatisticsUtils
                                .onEvent(StatisticsEventID.BOOKCONTENT_CLICK_REFLUSH_CHAPTER);
                    } else {
                        StatisticsUtils.onEvent(StatisticsEventID.BOOKCONTENT_CLICK_REFLUSH_BOOK);
                    }
                }
                StatisticsUtils.onEvent(StatisticsEventID.BOOKCOVER_ORDERDIALOG_REFRESH);
                break;
            case R.id.view_dialog_order_pay:
                Log4an.e(logTag, "余额充足：" + isBalanceEnough());
                if (isBalanceEnough()) {
                    if (context instanceof BookContentActivity) {
                        if (orderInfo != null) {
                            if (orderInfo.getPayMode() == 1) {
                                buyBook();
                            } else {
                                buyChapter();
                            }
                        } else {
                            Toast.makeText(context, "购买失败...", Toast.LENGTH_LONG).show();
                        }
                    } else if (context instanceof BookCoverActivity) {
                        handler.sendEmptyMessage(MSG_BUY_LOADING);
                    }
                    StatisticsUtils.onEvent(StatisticsEventID.BOOKCOVER_ORDERDIALOG_BUY);
                } else {
                    isOnclickPay = true;
                    dismiss();
                    Intent intent = new Intent(context, PayActivity.class);
                    if (context instanceof BookCoverActivity
                            && context.getParent() instanceof Activity) {
                        ActivityManager.getInstance().startNextActivityForResult(intent,
                                Constant.ORDER_REQUESTCOD, context);
                    } else {
                        ActivityManager.getInstance().startNextActivityForResult(intent,
                                Constant.ORDER_REQUESTCOD, context);
                    }
                    if (context instanceof BookContentActivity) {
                        if (orderInfo.getPayMode() == 1) {
                            StatisticsUtils
                                    .onEvent(StatisticsEventID.BOOKCONTENT_CLICK_RECHARG_BOOK);
                        } else {
                            StatisticsUtils
                                    .onEvent(StatisticsEventID.BOOKCONTENT_CLICK_RECHARG_CHAPTERE);
                        }
                    } else if (context instanceof BookCoverActivity) {
                        StatisticsUtils.onEvent(StatisticsEventID.BOOKCOVER_ORDERDIALOG_PAY);
                    }
                }
                break;
            case R.id.view_dialog_order_checkbox:

                BookInfoDao.getInstance().updateAutoBuyBookState(
                        orderInfo.getBookId(),
                        null,
                        MyAccountManager.getInstance(context).getUserId(),
                        (mCheckBox.isChecked() ? BookInfo.DEFAULT_NO_AUTO_BUY
                                : BookInfo.NO_AUTO_BUY));
                if (!mCheckBox.isChecked()) {
                    StatisticsUtils
                            .onEvent(StatisticsEventID.BOOKCONTENT_CLICK_CANCEL_AUTHORIZE_CHAPTER);
                }
                break;
        }
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        if (mOnOrderDialogListener != null) {
            mOnOrderDialogListener.onOrderDialogDismiss();
        }
    }

    /** 设置隐藏订单内容 */
    private void setGoneOrderContent() {
        view.findViewById(R.id.buyLoading).setVisibility(View.VISIBLE);
        view.findViewById(R.id.progressBar).setVisibility(View.VISIBLE);
        ((TextView) view.findViewById(R.id.buy_states)).setText(context.getResources().getString(
                R.string.bookcontent_order_loading));

        view.findViewById(R.id.buy_ok).setVisibility(View.GONE);
        view.findViewById(R.id.orderContent).setVisibility(View.GONE);

        dialog.setDissmisOnClickOutSide(false);
        dialog.setCancelable(false);
    }

    @Deprecated
    private void goneLoading() {
        dialog.setDissmisOnClickOutSide(true);
        view.findViewById(R.id.buyLoading).setVisibility(View.GONE);
        view.findViewById(R.id.progressBar).setVisibility(View.GONE);
        ((TextView) view.findViewById(R.id.buy_states)).setVisibility(View.GONE);
        view.findViewById(R.id.buy_ok).setVisibility(View.VISIBLE);
        view.findViewById(R.id.orderContent).setVisibility(View.VISIBLE);
    }

    /** 购买成功提示 */
    public void showBuySuccessful(boolean isShowDialog) {
        dialog.setDissmisOnClickOutSide(true);
        view.findViewById(R.id.progressBar).setVisibility(View.GONE);
        ((TextView) view.findViewById(R.id.buy_states)).setText("购买成功");
        view.findViewById(R.id.buy_ok).setVisibility(View.VISIBLE);
        ShuqiApplication.getApplicationHandler().postDelayed(new Runnable() {
            public void run() {
                dismiss();
            }
        }, 3000);

        // mOrderDialog.dismiss();
        // if (!isShowDialog) {
        // dismiss();
        // return;
        // }
        // dialog.setDissmisOnClickOutSide(true);
        // view.findViewById(R.id.progressBar).setVisibility(View.GONE);
        // if (bookInfo != null && !TextUtils.isEmpty(bookInfo.getMsg())) {
        // if (context instanceof BookContentActivity) {
        // if (context.isFinishing())
        // return;
        // }
        // if (isNight) {
        // BottomToastNight.makeToast(context, bookInfo.getMsg(),
        // R.drawable.common_icon_success).show();
        // } else {
        // BottomToast.makeToast(context, bookInfo.getMsg(), R.drawable.common_icon_success)
        // .show();
        // }
        // }
    }

    public void showBuyBookToast() {
        dialog.setDissmisOnClickOutSide(true);
        if (mBuyBookInfo != null && !TextUtils.isEmpty(mBuyBookInfo.getInfo())) {
            view.findViewById(R.id.progressBar).setVisibility(View.GONE);
            ((TextView) view.findViewById(R.id.buy_states)).setText(mBuyBookInfo.getInfo());
            view.findViewById(R.id.buy_ok).setVisibility(View.VISIBLE);
            ShuqiApplication.getApplicationHandler().postDelayed(new Runnable() {
                public void run() {
                    dismiss();
                }
            }, 3000);
        }

        // if (mBuyBookInfo != null && !TextUtils.isEmpty(mBuyBookInfo.getInfo())) {
        // if (context instanceof BookContentActivity) {
        // if (context.isFinishing())
        // return;
        // }
        // if (isNight) {
        // BottomToastNight.makeToast(context, mBuyBookInfo.getInfo(),
        // R.drawable.common_icon_success).show();
        // } else {
        // BottomToast.makeToast(context, mBuyBookInfo.getInfo(),
        // R.drawable.common_icon_success).show();
        // }
        // }
    }

    /** 购买失败提示 */
    public void showBuyFailed(String failureMessage) {
        dismiss();
        dialog.setDissmisOnClickOutSide(true);
        if (context instanceof BookContentActivity) {
            if (context.isFinishing())
                return;
        }
        if (isNight) {
            BottomToastNight.makeToast(context, failureMessage, R.drawable.common_icon_fail).show();
        } else {
            BottomToast.makeToast(context, failureMessage, R.drawable.common_icon_fail).show();
        }
    }

}
